package com.ie.cloud.payment.init;

import cn.hutool.core.util.StrUtil;
import com.ie.cloud.payment.cache.RedisUtil;
import com.ie.cloud.payment.constants.CS;
import com.ie.cloud.payment.entity.PayInterfaceDefine;
import com.ie.cloud.payment.mapper.PayInterfaceDefineMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created with FR
 *
 * @Author: DQ
 * @Date: 2025/07/23/14:50
 * @Description: 支付接口定义缓存
 */
@Component
@Slf4j
public class PayInterfaceDefineCacheInit implements CommandLineRunner {

    @Resource
    private PayInterfaceDefineMapper payInterfaceDefineMapper;


    @Override
    public void run(String... args) throws Exception {

        log.info("初始化支付接口定义缓存");

        List<PayInterfaceDefine> allPayInterfaceDefine = payInterfaceDefineMapper.
                selectList(PayInterfaceDefine.gw());

        for (PayInterfaceDefine payInterfaceDefine : allPayInterfaceDefine) {
            RedisUtil.set(
                    StrUtil.join(StrUtil.COLON,CS.PAY_INTERFACE_CACHE.PAY_INTERFACE_DEFINE_CACHE,payInterfaceDefine.getIfCode()),
                    payInterfaceDefine);
        }

        log.info("初始化支付接口定义缓存完成");

    }

    public static void main(String[] args) {
        System.out.println(StrUtil.join("","2222","3"));
    }
}
